/*
 * ScheduleDialog.java
 *
 * Created on 19 de Dezembro de 2004, 11:49
 */

package ceirinhashls.gui;
import ceirinhashls.util.Settings;
/**
 *
 * @author  botelhodaniel
 */
public class ScheduleDialog extends javax.swing.JDialog {
    /**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 3834033575627733049L;
	private MainFrame mf;
    private static long timeSelected=new Integer(Settings.SCHEDULED_HOUR).intValue()*60*60*1000+
    new Integer(((Settings.SCHEDULED_MIN).substring(1))).intValue()*60*1000;;
    /** Creates new form ScheduleDialog */
    public ScheduleDialog(MainFrame mf) {
        super(mf, true);
        timeSelected=-1;
        this.mf=mf;
        initComponents();
        update();
    }
    
    private void update(){
        jCheckBox1.setSelected(Settings.SCHEDULED);
        jComboBox1.setSelectedItem(Settings.SCHEDULED_HOUR);
        jComboBox1.setEnabled(jCheckBox1.isSelected());
        
        jComboBox2.setSelectedItem(Settings.SCHEDULED_MIN);
        jComboBox2.setEnabled(jCheckBox1.isSelected());
        jCheckBox2.setSelected(Settings.LOCAL_FILE);
        jCheckBox2.setEnabled(jCheckBox1.isSelected());
        jCheckBox3.setSelected(Settings.WEB_SERVER);
        jCheckBox3.setEnabled(jCheckBox1.isSelected());
        jCheckBox4.setSelected(Settings.PING_ALL);
        jCheckBox4.setEnabled(jCheckBox1.isSelected());
        if(Settings.SCHEDULED){
            timeSelected = 
            new Integer(""+jComboBox1.getSelectedItem()).intValue()*60*60*1000+
            new Integer(((jComboBox2.getSelectedItem()+"").substring(1))).intValue()*60*1000;
            System.out.println(jComboBox1.getSelectedItem()+""+jComboBox2.getSelectedItem());
            System.out.println(timeSelected);
        }
        
    }
    
    public static long getTime(){
    	return timeSelected;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jPanel3 = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        jPanel5 = new javax.swing.JPanel();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox4 = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        jButton1.setText(StringDef.OK);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jPanel2.add(jButton1);

        jButton2.setText(StringDef.CANCEL);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jPanel2.add(jButton2);

        getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);

        jPanel4.setLayout(new java.awt.BorderLayout());

        jCheckBox1.setText(StringDef.ENABLE_SCHEDULE);
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jPanel1.add(jCheckBox1);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "04", "08", "12", "18", "24" }));
        jPanel3.add(jComboBox1);

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { ":00", ":05", ":10", ":15", ":20", ":25", ":30", ":35", ":40", ":45", ":50", ":55" }));
        jPanel3.add(jComboBox2);

        jPanel1.add(jPanel3);

        jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER);

        jPanel5.setLayout(new java.awt.BorderLayout());

        jPanel5.setBorder(new javax.swing.border.TitledBorder(StringDef.TASKS));
        jCheckBox2.setText(StringDef.UPDATE_LOCAL);
        jCheckBox2.setEnabled(false);
        jPanel5.add(jCheckBox2, java.awt.BorderLayout.CENTER);

        jCheckBox3.setText(StringDef.UPDATE_WEBSERVER);
        jCheckBox3.setEnabled(false);
        jPanel5.add(jCheckBox3, java.awt.BorderLayout.NORTH);

        jCheckBox4.setText(StringDef.DO_PING);
        jCheckBox4.setEnabled(false);
        jPanel5.add(jCheckBox4, java.awt.BorderLayout.SOUTH);

        jPanel4.add(jPanel5, java.awt.BorderLayout.NORTH);

        getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);

        pack();
    }//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        update();
        this.setVisible(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        Settings.SCHEDULED = jCheckBox1.isSelected();
        Settings.SCHEDULED_HOUR = ""+jComboBox1.getSelectedItem();
        Settings.SCHEDULED_MIN = ""+jComboBox2.getSelectedItem();
        Settings.LOCAL_FILE = jCheckBox2.isSelected();
        Settings.WEB_SERVER = jCheckBox3.isSelected();
        Settings.PING_ALL = jCheckBox4.isSelected();
        update();
        this.setVisible(false);
        mf.setTimerEnable(Settings.SCHEDULED);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        // TODO add your handling code here:
        jComboBox1.setEnabled(jCheckBox1.isSelected());
        jComboBox2.setEnabled(jCheckBox1.isSelected());
        jCheckBox2.setEnabled(jCheckBox1.isSelected());
        jCheckBox3.setEnabled(jCheckBox1.isSelected());
        jCheckBox4.setEnabled(jCheckBox1.isSelected());
    }//GEN-LAST:event_jCheckBox1ActionPerformed
    
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JCheckBox jCheckBox4;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    // End of variables declaration//GEN-END:variables
    
}
